﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Basic.Model.Entity;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Criterion;

namespace Basic.Model.EntityManager
{
    public class AutoNumberManager
    {
        public static void AddAutoNumber(ISession session, AutoNumber an)
        {
            session.Save(an);
        }

        public static void DeleteAutoNumber(ISession session, AutoNumber an)
        {
            session.Delete(an);
        }

        public static AutoNumber GetAutoNumber(ISession session, string itemId)
        {
            return session.Get<AutoNumber>(itemId);
        }

        public static AutoNumber GetAutoNumberByTableName(ISession session, string tableName)
        {
            ICriteria c = session.CreateCriteria(typeof(AutoNumber));
            c.Add(Expression.Eq("tableName", tableName));
            return c.UniqueResult<AutoNumber>();
        }

        public static IList<AutoNumber> GetAllAutoNumber(ISession session)
        {
            ICriteria c = session.CreateCriteria(typeof(AutoNumber));
            return c.List<AutoNumber>();
        }
    }
}
